package com.example.my0612zuoye;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class MyListAdpater extends BaseAdapter {
    List<Phone.DataBean.PhonesBean>list;
    Context context;
    int [] py=new int[]{R.drawable.xiaomi4,R.drawable.ry6,R.drawable.sx6};

    public MyListAdpater(List<Phone.DataBean.PhonesBean> list, Context context) {
        this.list = list;
        this.context = context;

    }

    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }
    class ViewHodle{
        ImageView img_phone;
        TextView tv1,tv2,tv3;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodle vh;
        if (convertView==null){
            vh=new ViewHodle();
            convertView= LayoutInflater.from(context).inflate(R.layout.list_item,null);
            vh.img_phone=convertView.findViewById(R.id.img_phone);
            vh.tv1=convertView.findViewById(R.id.tv1);
            vh.tv2=convertView.findViewById(R.id.tv2);
            vh.tv3=convertView.findViewById(R.id.tv3);
            convertView.setTag(vh);
        }else {
            vh= (ViewHodle) convertView.getTag();
        }
        Phone.DataBean.PhonesBean phone=list.get(position);
        Log.e("getView: ",phone.getName() );
        vh.img_phone.setImageResource(py[position]);
        vh.tv1.setText("手机型号："+phone.getName());
        vh.tv2.setText("价钱："+phone.getPrice());
        vh.tv3.setText("品牌："+phone.getBrand());
        return convertView;
    }
}
